<template>
  <section v-loading="loading" class="cms-body">
    <div class="cms-list-header">
      <cms-input v-model="params.userName" label="用户名"></cms-input>
      <cms-input v-model="params.title" label="标题"></cms-input>
      <cms-input v-model="params.ip" label="IP"></cms-input>
      <el-date-picker
        format="yyyy-MM-dd"
        value-format="yyyy-MM-dd"
        v-model="params.queryTime"
        type="daterange"
        align="left"
        unlink-panels
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期">
      </el-date-picker>
      <label class="cms-label">日志类型</label>
      <el-select v-model="params.category" @change="goQuery" clearable>
        <el-option label="登录成功日志" value="1"></el-option>
        <el-option label="登录失败日志" value="2"></el-option>
        <el-option label="系统操作日志" value="3"></el-option>
        <el-option label="推送成功日志" value="4"></el-option>
        <el-option label="推送失败日志" value="5"></el-option>
      </el-select>
      <el-button @click="goQuery">查询</el-button>
    </div>
    <el-table :data="tableData" stripe style="width: 100%" @selection-change="checkIds">
      <el-table-column prop="id" label="ID" width="50" align="center"></el-table-column>
      <el-table-column v-if="params.category!=2" prop="userName" width="85" label="用户名"
                       align="center"></el-table-column>
      <el-table-column prop="logTime" label="时间" align="center" width="120"></el-table-column>
      <el-table-column prop="ip" label="IP" align="center" width="120"></el-table-column>
      <el-table-column prop="title" label="标题" align="center"></el-table-column>
      <el-table-column v-if="params.category!=1" prop="content" label="内容" align="left"></el-table-column>
    </el-table>
    <!-- 表格底部 -->
    <div class="cms-list-footer ">
      <div class="cms-left">
      </div>
      <!-- cms分页组件 -->
      <cms-pagination :total="total" @change="getPages"></cms-pagination>
    </div>
  </section>
</template>

<script>
  import listMixins from '@/mixins/list'

  export default {
    mixins: [listMixins],
    data() {
      return {
        params: {//只需要业务参数
          userName: "",
          title: "",
          ip: "",
          category: "",
          queryTime: "",
          startTime: '',
          endTime: '',
          pageNo: 1,
          pageSize: 10,
        }
      };
    },
    methods: {
      goQuery() {
        let queryTime = this.params.queryTime;
        if (!this.$myUtils.isNull(queryTime)) {
          for (let i in queryTime) {
            let time = queryTime[i];
            if (i == 0) {
              this.params['startTime'] = time;
            }
            if (i == 1) {
              this.params['endTime'] = time;
            }
          }
        }
        this.getTableData(this.params);
      },
    },
    created() {
      this.initTableData(this.$api.logPageList, this.params);
    }
  };
</script>


